//From jacwright: http://code.google.com/p/jacwright/source/browse/#svn/trunk/flash/jac_air/src/jac/ui
//http://jacwright.com/59/using-mxml-for-air-nativemenus/
package jac.ui
{
  import flash.display.NativeMenu;
  import flash.display.NativeMenuItem;
  import flash.system.Capabilities;

  [DefaultProperty("items")]
  /**
   * Our main menu control, wraps the OS native menus
   */
  public class Menu extends NativeMenu
  {
    [ArrayElementType("flash.display.NativeMenuItem")]
    public override function set items(value:Array):void
    {
      while (numItems)
      {
        removeItemAt(0);
      }

      var os:String = Capabilities.os.substring(0, 3).toLowerCase();

      for each (var item:NativeMenuItem in value)
      {
        if (item is MenuItem && MenuItem(item).os && MenuItem(item).os.toLowerCase().indexOf(os) == -1)
        {
          continue;
        }

        addItem(item);
      }
    }
  }
}
